package com.example.demo.algorithms;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

/**
 * @author Eric Lee
 * @version v1.0.0
 * @since 2021/4/15 17:31
 **/
public class DisjoinSet {

    public static void main(String[] args) {
        Integer[] s1 = {2, 4, 5, 6};  // 有序，不重复
        Integer[] s2 = {7, 8, 9, 10};   // 有序，不重复
        disjoinSet(s1, s2); 
    }

    public static void disjoinSet(Integer[] A, Integer[] B) {
        TreeSet<Integer> T = new TreeSet<>();
        int n = A.length;
        for (int i = 0; i < n; i++) {
            T.add(A[i]);
        }
        TreeSet<Integer> commSet = new TreeSet<>();
        for (int j = 0; j < n; j++) {
            if (T.contains(B[j])) {
                commSet.add(B[j]);
            }
        }
        List cList = new ArrayList();
        List dList = new ArrayList();
        for (int i = 0; i < n; i++) {
            if (!commSet.contains(A[i]) && !commSet.contains(B[i])) {
                cList.add(A[i]);
                dList.add(B[i]);
            }
        }
        System.out.println("C:" + cList.toString());
        System.out.println("D:" + dList.toString());

    }
}
